package so.shanku.essential.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.tsz.afinal.json.JsonMap;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;
import so.shanku.essential.R;
import so.shanku.essential.app.MyApplication;
import so.shanku.essential.utils.ImageLoaderBitmapCallBack;
import so.shanku.essential.utils.StringUtil;

import java.util.List;
import java.util.Map;

/**
 * Created by Jaelyn on 2015/10/10 0010.
 */
public class ShopAddOrderProductAdapter extends MyBaseAdapter {
	public ShopAddOrderProductAdapter(Context context) {
		super(context);
	}

	public ShopAddOrderProductAdapter(Context context, List<? extends Map<String, ?>> datas) {
		super(context, datas);
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {

		ShopAddOrderGoodsAdapterViewHolder shopCartAdapterViewHolder;
		if (view == null) {
			view = layoutInflater.inflate(R.layout.item_shopping_addrder, null);
			shopCartAdapterViewHolder = new ShopAddOrderGoodsAdapterViewHolder();
			ViewUtils.inject(shopCartAdapterViewHolder, view);
			view.setTag(shopCartAdapterViewHolder);
		} else {
			shopCartAdapterViewHolder = (ShopAddOrderGoodsAdapterViewHolder) view.getTag();
		}
		bindDatas(i, shopCartAdapterViewHolder);
		return view;
	}


	private void bindDatas(int i, ShopAddOrderGoodsAdapterViewHolder shopCartAdapterViewHolder) {
		JsonMap jsonMap = (JsonMap) datas.get(i);

		shopCartAdapterViewHolder.i_s_a_o_tv_productname.setText(jsonMap.getStringNoNull("ProductSaleName"));
		shopCartAdapterViewHolder.i_s_a_o_tv_productnum.setText(context.getString(R.string.shopping_tv_text_productnum_qz)+jsonMap.getStringNoNull("Amount"));
		shopCartAdapterViewHolder.goods_discribe_tv.setText(jsonMap.getStringNoNull("speStrName"));
        shopCartAdapterViewHolder.goods_price_tv.setText(StringUtil.getFormatMoneyWithSign(jsonMap.getStringNoNull("ProductPrice")));
        String str = jsonMap.getStringNoNull("ProductPic");
		if (MyApplication.getInstance().getBitmapHashMap().containsKey(str)) {
			shopCartAdapterViewHolder.i_s_pl_aiv_pic1.setImageBitmap(MyApplication.getInstance().getBitmapHashMap().get(str));
		} else {
			ImageLoader.getInstance().displayImage(str, shopCartAdapterViewHolder.i_s_pl_aiv_pic1, MyApplication.getInstance().getDefaultOption(), new ImageLoaderBitmapCallBack());
		}
	}

	class ShopAddOrderGoodsAdapterViewHolder {
		@ViewInject(R.id.i_s_a_o_tv_productname)
		TextView i_s_a_o_tv_productname;
		@ViewInject(R.id.i_s_a_o_tv_productnum)
		TextView i_s_a_o_tv_productnum;
		@ViewInject(R.id.productBrand_tv)
		TextView goods_discribe_tv;
		@ViewInject(R.id.i_s_pl_aiv_pic1)
		ImageView i_s_pl_aiv_pic1;
        @ViewInject(R.id.goods_price_tv)
        TextView goods_price_tv;
	}
}
